<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<link	href="css/style.css" rel="stylesheet" type="text/css" />
<link  href="admin/css/jsDatePick_ltr.min.css" rel="stylesheet" type="text/css" media="all" />
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />
<script type="text/javascript" src="js/jquery.autocomplete.js"></script>
<script type="text/javascript" src="js/accouting.js"></script>
<script type="text/javascript" src="admin/css/jsDatePick.min.1.3.js"></script>
<script type="text/javascript" src="js/jquery.price_format.1.7.js"></script>
<script type="text/javascript" src="js/jquery.price_format.1.7.min.js"></script>
<script src="js/jquery-ui.js"></script>
<link href="css/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
    $(function() {
    	onLoad();
    });
    function onLoad(){
        var tabs = $( "#tabs" ).tabs();
        tabs.find( ".ui-tabs-nav" ).sortable({
            axis: "x",
            stop: function() {
                tabs.tabs( "refresh" );
            }
        });
        new JsDatePick({
            useMode:2,
            target:"addsignDay",
            dateFormat:"%Y-%m-%d"
        });
        new JsDatePick({
            useMode:2,
            target:"addstartDay1",
            dateFormat:"%Y-%m-%d"
        });
    	new JsDatePick({
            useMode:2,
            target:"addendDay1",
            dateFormat:"%Y-%m-%d"
        });
    	$('#addprice').priceFormat({
            prefix: '',
            centsLimit: 0,
            centsSeparator: '',
            thousandsSeparator: ''
    	
        });
    	$('#addprice1').priceFormat({
            prefix: '',
            centsLimit: 0,
            centsSeparator: '',
            thousandsSeparator: ''
    	
        });
    }
    function oneditLoad1(){
    	new JsDatePick({
            useMode:2,
            target:"editstartDay1",
            dateFormat:"%Y-%m-%d"
        });
    	new JsDatePick({
            useMode:2,
            target:"editendDay1",
            dateFormat:"%Y-%m-%d"
        });
       
    	$('#editprice1').priceFormat({
            prefix: '',
            centsLimit: 0,
            centsSeparator: '',
            thousandsSeparator: ''
    	
        });
    }	
    function oneditLoad(){
        new JsDatePick({
            useMode:2,
            target:"editsignDay",
            dateFormat:"%Y-%m-%d"
        });
    	$('#editprice').priceFormat({
            prefix: '',
            centsLimit: 0,
            centsSeparator: '',
            thousandsSeparator: ''
    	
        });
    }	
    function delProduct(id){
        var hoi =confirm("<?=$l_areyousure?>");
        if(hoi==true){
        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                document.getElementById("listnameProduct").innerHTML=xmlhttp.responseText;
                document.getElementById("listcontractwarranty").innerHTML="";
            	document.getElementById("listcompany").innerHTML="";
            	document.getElementById("listcontractwarrantydetail").innerHTML="";
            }
        }
        xmlhttp.open("GET","content_contractwarranty/delProduct.php?id="+id,true);
        xmlhttp.send();
        }

	
	}
    function showeditProduct(id,name){
    	document.getElementById("editidProduct").value=id;
    	document.getElementById("editnameProduct").value=name;
    	popup_window_show('#sample2', { pos : 'window-center', width : '320px', height:'800px'});
    }
    function editProduct(){
    	var id=document.getElementById("editidProduct").value;
        var nameProduct=document.getElementById("editnameProduct").value;
        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                document.getElementById("listnameProduct").innerHTML=xmlhttp.responseText;
                document.getElementById("listcontractwarranty").innerHTML="";
            	document.getElementById("listcompany").innerHTML="";
            	document.getElementById("listcontractwarrantydetail").innerHTML="";
            }
        }
        xmlhttp.open("GET","content_contractwarranty/editProduct.php?id="+id+"&nameProduct="+nameProduct,true);
        xmlhttp.send();
	}
    function addProduct(){
        var nameProduct=document.getElementById("addnameProduct").value;
        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                document.getElementById("listnameProduct").innerHTML=xmlhttp.responseText;
                document.getElementById("listcontractwarranty").innerHTML="";
            	document.getElementById("listcompany").innerHTML="";
            	document.getElementById("listcontractwarrantydetail").innerHTML="";;
            }
        }
        xmlhttp.open("GET","content_contractwarranty/addProduct.php?nameProduct="+nameProduct,true);
        xmlhttp.send();
	}
    function checkonlyProduct(id){
    	
    	if(document.getElementById(id).checked == true){
    		document.getElementById("listcontractwarranty").innerHTML="";
    		
    		var x=document.getElementsByName("checkProduct");
        	for(var i = 0;i<x.length;i++)
            {
        		document.getElementById('checkProduct'+i).checked = false;
            	//document.getElementsbyname('checkProduct')[i].checked = true ;
            }
        	document.getElementById("listcontractwarrantydetail").innerHTML="";;
            document.getElementById(id).checked = true;
            var id_product=document.getElementById(id).value;
            loadlistcompany(id_product);
		
        }else{
        	document.getElementById("listcontractwarranty").innerHTML="";
        	document.getElementById("listcompany").innerHTML="";
        	document.getElementById("listcontractwarrantydetail").innerHTML="";
            document.getElementById(id).checked=false;
		
        }
    }
    function loadlistcompany(id_product){
    	
        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                document.getElementById("listcompany").innerHTML=xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","content_contractwarranty/loadlistcompany.php?id_product="+id_product,true);
        xmlhttp.send();
    }
    function showaddCompany(id_product){
    	document.getElementById("addidproduct").value=id_product;
    	//popup_window_show('#sample3', { pos : 'window-center', width : '320px', height:'800px'});
    	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                document.getElementById("frmaddcompany").innerHTML=xmlhttp.responseText;
                popup_window_show('#sample3', { pos : 'window-center', width : '320px', height:'800px'});
            }
        }
        xmlhttp.open("GET","content_contractwarranty/showaddcompany.php",true);
        xmlhttp.send();
    }
    function addnameCompany(){
    	var value=document.getElementById("addnameCompany").value;
    	if(value!=""){
	        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
	            xmlhttp=new XMLHttpRequest();
	        }else{// code for IE6, IE5
	            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	        }
	        xmlhttp.onreadystatechange=function(){
	            if (xmlhttp.readyState==4 && xmlhttp.status==200){
	                alert("<?=$l_themthanhcong?>");
	            	document.getElementById("addnameCompany").value="";
	            	document.getElementById("listaddidcompany").innerHTML=xmlhttp.responseText;
	            }
	        }
	        xmlhttp.open("GET","content_contractwarranty/addnameCompany.php?value="+value,true);
	        xmlhttp.send();
		}
	}
    function addCompany(){
    	var id_product=document.getElementById("addidproduct").value;
    	var id_company=document.getElementById("addidcompany").value;
        
        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                //alert(xmlhttp.responseText);
            	loadlistcompany(id_product);
            	document.getElementById("listcontractwarranty").innerHTML="";
            	document.getElementById("listcontractwarrantydetail").innerHTML="";
            }
        }
        xmlhttp.open("GET","content_contractwarranty/addCompany.php?id_product="+id_product+"&id_company="+id_company,true);
        xmlhttp.send();
	
	}
	function checkonlyCompany(id){
    	
    	if(document.getElementById(id).checked == true){
    		var x=document.getElementsByName("checkCompany");
        	for(var i = 0;i<x.length;i++)
            {
        		document.getElementById('checkCompany'+i).checked = false;
            	//document.getElementsbyname('checkProduct')[i].checked = true ;
            }
        	document.getElementById("listcontractwarrantydetail").innerHTML="";
            document.getElementById(id).checked = true;
            var id_warranty=document.getElementById(id).value;
            loadlistcontractw(id_warranty);
		
        }else{
        	document.getElementById("listcontractwarranty").innerHTML="";
        	document.getElementById("listcontractwarrantydetail").innerHTML="";
            document.getElementById(id).checked=false;
		
        }
    }
	function loadlistcontractw(id_warranty){
    	
        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                document.getElementById("listcontractwarranty").innerHTML=xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","content_contractwarranty/loadlistcontractw.php?id_warranty="+id_warranty,true);
        xmlhttp.send();
    }
    
	function delCompany(id_warranty,id_product){
        var hoi =confirm("<?=$l_areyousure?>");
        if(hoi==true){
        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
            	loadlistcompany(id_product);
            	document.getElementById("listcontractwarranty").innerHTML="";
            	document.getElementById("listcontractwarrantydetail").innerHTML="";
            }
        }
        xmlhttp.open("GET","content_contractwarranty/delCompany.php?id_warranty="+id_warranty,true);
        xmlhttp.send();
        }

	
	}

	function delOneRow(id,id_warranty){
        var hoi =confirm("<?=$l_areyousure?>");
        if(hoi==true){
        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                
            	loadlistcontractw(id_warranty);
            	document.getElementById("listcontractwarrantydetail").innerHTML="";
            }
        }
        xmlhttp.open("GET","content_contractwarranty/delOneRow.php?id="+id,true);
        xmlhttp.send();
        }

	
	}
	function showaddOneRow(id_warranty){
    	
    	document.getElementById("addidwarranty").value=id_warranty;
    	var d = new Date();
        var curr_date = d.getDate();
        var curr_month = d.getMonth() + 1; //Months are zero based
        var curr_year = d.getFullYear();
        var d1=curr_year + "-" + curr_month + "-" + curr_date;
    	document.getElementById("addsignDay").value=d1;
    	
    	popup_window_show('#sample6', { pos : 'window-center', width : '320px', height:'800px'});
    }
	function addOneRow(){
    	
    	var name=document.getElementById("addname").value;
    	var signDay=document.getElementById("addsignDay").value;
    	var price=document.getElementById("addprice").value;
    	var id_warranty=document.getElementById("addidwarranty").value;
    	var content=document.getElementById("addcontent").value;
    	var note=document.getElementById("addnote").value;
    	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
            	var d = new Date();
                var curr_date = d.getDate();
                var curr_month = d.getMonth() + 1; //Months are zero based
                var curr_year = d.getFullYear();
                var d1=curr_year + "-" + curr_month + "-" + curr_date;
                
            	document.getElementById("addname").value="";
            	document.getElementById("addsignDay").value=d1;
            	document.getElementById("addprice").value="";
            	document.getElementById("addidwarranty").value="";
            	document.getElementById("addcontent").value="";
            	document.getElementById("addnote").value="";
            	loadlistcontractw(id_warranty);
            	document.getElementById("listcontractwarrantydetail").innerHTML="";
            }
        }
        xmlhttp.open("GET","content_contractwarranty/addOneRow.php?name="+name+"&signDay="+signDay+"&id_warranty="+id_warranty+"&price="+price+"&content="+content+"&note="+note,true);
        xmlhttp.send();
    }

	function showeditOneRow(id,id_warranty){
    	
    	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                document.getElementById("frmeditcontractwarranty").innerHTML=xmlhttp.responseText;
            	document.getElementById("editidwarranty").value=id_warranty;
                oneditLoad();
                popup_window_show('#sample7', { pos : 'window-center', width : '320px', height:'800px'});
            }
        }
        xmlhttp.open("GET","content_contractwarranty/showeditOneRow.php?id="+id,true);
        xmlhttp.send();
    }

    function editOneRow(){
    	var id=document.getElementById("editid_contractwarranty").value;
    	var name=document.getElementById("editname").value;
    	var signDay=document.getElementById("editsignDay").value;
    	var price=document.getElementById("editprice").value;
    	var id_warranty=document.getElementById("editidwarranty").value;
    	var content=document.getElementById("editcontent").value;
    	var note=document.getElementById("editnote").value;
    	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
            	loadlistcontractw(id_warranty);
            	document.getElementById("listcontractwarrantydetail").innerHTML="";
            }
        }
        xmlhttp.open("GET","content_contractwarranty/editOneRow.php?id="+id+"&name="+name+"&signDay="+signDay+"&price="+price+"&content="+content+"&note="+note,true);
        xmlhttp.send();
    }

function checkonlyContractw(id){
    	
    	if(document.getElementById(id).checked == true){
    		var x=document.getElementsByName("checkContractw");
        	for(var i = 0;i<x.length;i++)
            {
        		document.getElementById('checkContractw'+i).checked = false;
            	//document.getElementsbyname('checkProduct')[i].checked = true ;
            }
            document.getElementById(id).checked = true;
            var id_contractw=document.getElementById(id).value;
            loadlistcontractwd(id_contractw);
            document.getElementById("listcontractwarrantydetail").innerHTML="";
		
        }else{
            document.getElementById(id).checked=false;
            document.getElementById("listcontractwarrantydetail").innerHTML="";
		
        }
    }
function loadlistcontractwd(id_contractw){
    if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }else{// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function(){
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
            document.getElementById("listcontractwarrantydetail").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","content_contractwarranty/loadlistcontractwd.php?id_contractw="+id_contractw,true);
    xmlhttp.send();
}
function delOneRow1(id,id_contractw){
    var hoi =confirm("<?=$l_areyousure?>");
    if(hoi==true){
    if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }else{// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function(){
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
        	loadlistcontractwd(id_contractw);
        }
    }
    xmlhttp.open("GET","content_contractwarranty/delOneRow1.php?id="+id,true);
    xmlhttp.send();
    }


}

function showaddOneRow1(id_contractw){
	
	document.getElementById("addidcontractw").value=id_contractw;
	var d = new Date();
    var curr_date = d.getDate();
    var curr_month = d.getMonth() + 1; //Months are zero based
    var curr_year = d.getFullYear();
    var d1=curr_year + "-" + curr_month + "-" + curr_date;
	document.getElementById("addstartDay1").value=d1;
	document.getElementById("addendDay1").value=d1;
	
	popup_window_show('#sample8', { pos : 'window-center', width : '320px', height:'800px'});
}
function addOneRow1(){
	var name=document.getElementById("addname1").value;
	var startDay=document.getElementById("addstartDay1").value;
	var endDay=document.getElementById("addendDay1").value;
	var price=document.getElementById("addprice1").value;
	var id_contractw=document.getElementById("addidcontractw").value;
	var company=document.getElementById("addcompany1").value;
	var note=document.getElementById("addnote1").value;
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }else{// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function(){
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
        	var d = new Date();
            var curr_date = d.getDate();
            var curr_month = d.getMonth() + 1; //Months are zero based
            var curr_year = d.getFullYear();
            var d1=curr_year + "-" + curr_month + "-" + curr_date;
            
        	document.getElementById("addname1").value="";
        	document.getElementById("addstartDay1").value=d1;
        	document.getElementById("addendDay1").value=d1;
        	document.getElementById("addprice1").value="";
        	document.getElementById("addidcontractw").value="";
        	document.getElementById("addcompany1").value="";
        	document.getElementById("addnote1").value="";
        	loadlistcontractwd(id_contractw);
        }
    }
    xmlhttp.open("GET","content_contractwarranty/addOneRow1.php?name="+name+"&startDay="+startDay+"&endDay="+endDay+"&id_contractw="+id_contractw+"&price="+price+"&company="+company+"&note="+note,true);
    xmlhttp.send();
}

function showeditOneRow1(id,id_contractw){
	
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }else{// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function(){
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
            document.getElementById("frmeditcontractcontractw").innerHTML=xmlhttp.responseText;
        	document.getElementById("editidcontractw").value=id_contractw;
            oneditLoad1();
            popup_window_show('#sample9', { pos : 'window-center', width : '320px', height:'800px'});
        }
    }
    xmlhttp.open("GET","content_contractwarranty/showeditOneRow1.php?id="+id,true);
    xmlhttp.send();
}

function editOneRow1(){
	var id=document.getElementById("editid_contractw").value;
	var name=document.getElementById("editname1").value;
	var startDay=document.getElementById("editstartDay1").value;
	var endDay=document.getElementById("editendDay1").value;
	var price=document.getElementById("editprice1").value;
	var id_contractw=document.getElementById("editidcontractw").value;
	var company=document.getElementById("editcompany1").value;
	var note=document.getElementById("editnote1").value;
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }else{// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function(){
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
        	loadlistcontractwd(id_contractw);
        }
    }
    xmlhttp.open("GET","content_contractwarranty/editOneRow1.php?id="+id+"&name="+name+"&startDay="+startDay+"&endDay="+endDay+"&price="+price+"&company="+company+"&note="+note,true);
    xmlhttp.send();
}
</script>
<?php 
$nameProduct= array();
$result = mysql_query("SELECT p.* FROM contract_nameProduct p WHERE p.isDelete=0;");
while ($r = mysql_fetch_array($result)) {
    $nameProduct[] = array($r['id'], $r['name']);
}
include 'content_contractwarranty/popup_addProduct.php';
include 'content_contractwarranty/popup_editProduct.php';


$companys= array();
$result = mysql_query("SELECT c.* FROM contract_company c WHERE c.isDelete=0;");
while ($r = mysql_fetch_array($result)) {
    $companys[] = array($r['id'], $r['name']);
}
$company= array();
include 'content_contractwarranty/popup_addCompany.php';
//$result = mysql_query("SELECT c.*,w.id as id_warranty from warranty w,contract_company c  WHERE w.id_product=2 AND c.id=w.id_company AND c.isDelete=0");
//while ($r = mysql_fetch_array($result)) {
//    $company[] = array($r['id'], $r['name'],$r['is_warranty']);
//}


$contractw= array();
//$result = mysql_query("SELECT c.* FROM contract_warranty c WHERE c.isDelete=0 AND c.id_warranty=8");
//while ($r = mysql_fetch_array($result)) {
//    	$contractw[] = array($r['id'],$r['serial'],$r['name'],$r['startDay'],$r['endDay'],$r['price'],$r['note']);
//}
include 'content_contractwarranty/popup_addOneRow.php';
include 'content_contractwarranty/popup_editOneRow.php';


$contractwd= array();
//$result = mysql_query("SELECT * FROM contract_warranty_detail d WHERE d.id_contract=1 AND d.isDelete=0");
//while ($r = mysql_fetch_array($result)) {
//    	$contractwd[] = array($r['id'],$r['name'],$r['startDay'],$r['endDay'],$r['price'],$r['company'],$r['note']);
//}

include 'content_contractwarranty/popup_addOneRow1.php';
include 'content_contractwarranty/popup_editOneRow1.php';
?>
<div id="contains" style="height:100%;">
    <div class="title" style="padding-top: 5px;font-weight: bold;"><?=$l_contractwarranty?></div>
    <div class="content_code" style="height:100%;">
        <div class="approval-right" style="padding-right:10px; height:100%;">
            <div id="tabs">
                <ul style="padding-left:0">
                    <li class="tabpc" style="background: url(images/tabpc.png) no-repeat;"><a href="#tabs-1" id="tab1" onclick="document.getElementById('tab1').setAttribute('style','color:blue;');document.getElementById('tab2').setAttribute('style','color:white;');" style="color: blue;"><?=$l_addcontractwarranty?></a></li>
                    <!-- <li class="taban" style="background: url(images/tabpc.png) no-repeat;"><a href="#tabs-2" id="tab2" onclick="document.getElementById('tab2').setAttribute('style','color:blue;');document.getElementById('tab1').setAttribute('style','color:white;');">Tim hop dong</a></li> -->
                </ul>
                <div class="clear"></div>
                <div id="tabs-1">
                    <div  style="width:100%;" >
                            <div style="min-height: 220px;padding-top: 10px;" >
                            	
                            	<table>
                            	<tr><td style="vertical-align: top;min-width: 300px;">
	                            	<div id="listnameProduct">
	                            	<?=$l_listproduct?>
                                	<br>
	                                <table cellpadding="0" cellspacing="1" border="0" class="ftable1" style="padding: 0 5px 0 10px; margin-top: 10px;">
	                                    <tr>
	                                        <th style="width: 30px"><img onclick="popup_window_show('#sample1', { pos : 'window-center', width : '320px', height:'800px'});" src="images/plus.png" style="cursor:pointer;" title="<?=$l_add?>"></th>
	                                        <th style="width: 30px"></th>
	                                        <th style="width: 30px"></th>
	                                        <!-- <th style="width: 30px"></th> -->
	                                        <th style="width: 200px"><?=$l_nameProduct_contract?></th>
	                                    </tr>
	                                    
	                                    <?php
	                                            $i = 0;
	                                            foreach ($nameProduct as $value => $giatri) {
	                                                ?>
	                                        <tr>
	                                            <td><?= $i + 1 ?></td>
	                                            <td><input type="checkbox" name="checkProduct" id="<?php echo 'checkProduct' . $i ?>" onclick="checkonlyProduct(this.id);"   value="<?= $giatri[0]?>" /></td>
	                                            <td><img onclick="delProduct('<?=$giatri[0]?>');" src="images/del.png" style="cursor:pointer;" title="<?=$l_delete?>"></td>
	                                            <!-- <td><img onclick="showeditProduct('<?=$giatri[0]?>','<?=$giatri[1]?>');" src="images/editn.png" style="cursor:pointer;" title="<?=$l_edit?>"></td> -->
	                                            <td style="text-align: left;padding-left: 10px;"><a onclick="showeditProduct('<?=$giatri[0]?>','<?=$giatri[1]?>');"><?php echo $giatri[1]; ?></a></td>
	                                        </tr>
										<?php
										    		$i++;
												}
										?>	
										<?php if($i==0){?>
	                                  	<tr><td colspan="3" style="text-align: left;"><?=$l_list_emplty?></td></tr>
	                                    <?php }?>
	                                </table>
	                                </div>
                                </td> 
                                <td style="vertical-align: top;min-width: 250px;">
                               
	                                <div id="listcompany">
	                                <?php if(count($company)>0){?>
	                                <?=$l_listcompany?>
                                	<br>
	                                <table cellpadding="0" cellspacing="1" border="0" class="ftable1" style="padding: 0 5px 0 10px; margin-top: 10px;">
	                                    <tr>
	                                        <th style="width: 30px"><img onclick="showaddCompany(<?=$id_product?>)" src="images/plus.png" style="cursor:pointer;" title="<?=$l_add?>"></th>
	                                        <th style="width: 30px"></th>
	                                        <th style="width: 30px"></th>
	                                        <th style="width: 200px"><?=$l_nameCompany_contract?></th>
	                                    </tr>
	                                    
	                                    <?php
	                                            $i = 0;
	                                            foreach ($company as $value => $giatri) {
	                                                ?>
	                                        <tr>
	                                            <td><?= $i + 1 ?></td>
	                                            <td><input type="checkbox" name="checkCompany" id="<?php echo 'checkCompany' . $i ?>" onclick="checkonlyCompany(this.id);"   value="<?= $giatri[2]?>" /></td>
	                                            <td><img onclick="delCompany('<?=$giatri[2]?>','<?=$id_product?>');" src="images/del.png" style="cursor:pointer;" title="<?=$l_delete?>"></td>
	                                            <td style="text-align: left;padding-left: 10px;"><?php echo $giatri[1]; ?></td>
	                                        </tr>
										<?php
										    		$i++;
												}
										?>	
										<?php if($i==0){?>
	                                  	<tr><td colspan="4" style="text-align: left;"><?=$l_list_emplty?></td></tr>
	                                    <?php }?>
	                                </table>
	                                <?php }?>
	                                </div>
	                                
                                </td>
                                <td style="vertical-align: top;min-width: 600px;">
	                                <div id="listcontractwarranty">
	                                <?php if(count($contractw)>0){?>
	                                <?=$l_listcontractwarranty?>
                                	<br>
	                                <table cellpadding="0" cellspacing="1" border="0" class="ftable1" style="padding: 0 5px 0 10px; margin-top: 10px;">
	                                    <tr>
	                                        <th style="width: 30px"><img onclick="showaddOneRow('<?=$id_warranty?>')" src="images/plus.png" style="width:20px;height:20px;cursor:pointer;" title="<?=$l_add?>"></th>
	                                        <th style="width: 30px"></th>
	                                        <th style="width: 100px"><?=$l_code_contractwarranty?></th>
	                                        <th style="width: 200px"><?=$l_name_contractwarranty?></th>
	                                        <th style="width: 110px"><?=$l_startDay?></th>
	                                        <th style="width: 110px"><?=$l_endDay?></th>
	                                        <th style="width: 100px"><?=$l_totalValue_contractwarranty?></th>
	                                        <th style="width: 80px"><?=$l_note?></th>
	                                    </tr> 
	                                    <?php
	                                            $i = 0;
	                                            foreach ($contractw as $value => $giatri) {
	                                                ?>
	                                        <tr>
	                                            <td><?= $i + 1 ?></td>
	                                            <td><img onclick="delOneRow('<?=$giatri[0]?>','<?=$id_warranty?>');" src="images/del.png" style="width:20px;height:20px;cursor:pointer;" title="<?=$l_delete?>"></td>
	                                            <td style="text-align: left;padding-left: 10px;"><a onclick="showeditOneRow('<?=$giatri[0]?>','<?=$id_warranty?>')"><?php echo $giatri[1]; ?></a></td>
	                                            <td style="text-align: left;padding-left: 10px;"><a onclick="showeditOneRow('<?=$giatri[0]?>','<?=$id_warranty?>')"><?php echo $giatri[2]; ?></a></td>
	                                            <td style="text-align: left;padding-left: 10px;"><?php echo $giatri[3]; ?></td>
	                                            <td style="text-align: left;padding-left: 10px;"><?php echo $giatri[4]; ?></td>
	                                            <td style="text-align: left;padding-left: 10px;"><?php echo number_format($giatri[5]); ?></td>
	                                            <td style="text-align: left;padding-left: 10px;"><?php echo $giatri[6]; ?></td>
	                                        </tr>
										<?php
										    		$i++;
												}
										?>	
										<?php if($i==0){?>
	                                  	<tr><td colspan="9" style="text-align: left;"><?=$l_list_emplty?></td></tr>
	                                    <?php }?>
	                                </table>
	                                <?php }?>
	                                </div>
                                </td>
                                </tr>
                                <tr>
                                	<td colspan="3">
                                	<div id="listcontractwarrantydetail" style="padding-top: 10px;">
                                	 <?php if(count($contractwd)>0){?>
	                                <?=$l_listcontractwarranty?>
                                	<br>
	                                <table cellpadding="0" cellspacing="1" border="0" class="ftable1" style="padding: 0 5px 0 10px; margin-top: 10px;">
	                                    <tr>
	                                        <th style="width: 30px"><img onclick="showaddOneRow('<?=$id_warranty?>')" src="images/plus.png" style="width:20px;height:20px;cursor:pointer;" title="<?=$l_add?>"></th>
	                                        <th style="width: 30px"></th>
	                                        <th style="width: 200px"><?=$l_name_contractwarranty?></th>
	                                        <th style="width: 110px"><?=$l_startDay?></th>
	                                        <th style="width: 110px"><?=$l_endDay?></th>
	                                        <th style="width: 100px"><?=$l_totalValue_contractwarranty?></th>
	                                        <th style="width: 80px"><?=$l_nameCompany_contractwarranty?></th>
	                                        <th style="width: 80px"><?=$l_note?></th>
	                                    </tr> 
	                                    <?php
	                                            $i = 0;
	                                            foreach ($contractwd as $value => $giatri) {
	                                                ?>
	                                        <tr>
	                                            <td><?= $i + 1 ?></td>
	                                            <td><img onclick="delOneRow('<?=$giatri[0]?>','<?=$id_warranty?>');" src="images/del.png" style="width:20px;height:20px;cursor:pointer;" title="<?=$l_delete?>"></td>
	                                            <td style="text-align: left;padding-left: 10px;"><a onclick="showeditOneRow('<?=$giatri[0]?>','<?=$id_warranty?>')"><?php echo $giatri[1]; ?></a></td>
	                                            <td style="text-align: left;padding-left: 10px;"><?php echo $giatri[2]; ?></td>
	                                            <td style="text-align: left;padding-left: 10px;"><?php echo $giatri[3]; ?></td>
	                                            <td style="text-align: left;padding-left: 10px;"><?php echo number_format($giatri[4]); ?></td>
	                                            <td style="text-align: left;padding-left: 10px;"><?php echo $giatri[5]; ?></td>
	                                            <td style="text-align: left;padding-left: 10px;"><?php echo $giatri[6]; ?></td>
	                                        </tr>
										<?php
										    		$i++;
												}
										?>	
										<?php if($i==0){?>
	                                  	<tr><td colspan="9" style="text-align: left;"><?=$l_list_emplty?></td></tr>
	                                    <?php }?>
	                                </table>
	                                <?php }?>
	                                </div>
                                	</td>
                                </tr>
                              
                                </table>
                                
                            </div>
                            

                    </div>
                    <br><br>
                   
                </div>


                <!-- <div id="tabs-2">
         asdasdas
                </div> -->

            </div>        
        </div>

    </div>


</div>
<?php mysql_close($connection); ?>